/**
 * 
 */
package jm.lib.common.db;

/**
 * @author JimingLiu
 *
 */
public class SearchConditionHelper {
	/**
	 * Wrap the <code>SearchCondition</code>'s value to 
	 * older <code>sc.value</code> days from current day
	 * If <code>sc.value</code> is start with <strong>-</strong>, 
	 * the <code>sc</code> will be disabled 
	 * @param sc
	 * @param dd
	 */
	public static void newerInDays(SimpleSearchCondition sc, DbDialect dd) {
		if(sc.getValue().startsWith("-")) {
			sc.setDisabled(true);
			return;
		}
		if(dd == DbDialect.MYSQL) {
			sc.setValue("(CURDATE()-"+sc.getValue()+")");
		} else if (dd == DbDialect.ORACLE) {
			
		}
		sc.setTrusted(true);
		sc.setWithQuotation(false);
	}
    
    /**
     * Create a composite SearchCondition with OR relationship
     * @param conditions
     */
    public static SearchCondition createOrConditions(SearchCondition ... conditions) {
        return new CompositeSearchCondition(conditions);
    }
	
    /**
     * Create a composite SearchCondition with AND relationship
     * @param conditions
     */
    public static SearchCondition createAndConditions(SearchCondition ... conditions) {
        return new CompositeSearchCondition(false, conditions);
    }
    
    public static SearchCondition createStringConditions(String condition) {
        return new StringSearchCondition(condition);
    }
    
}
